package com.example.love_margin.Mapper;


import com.example.love_margin.Entity.Test;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;


@Mapper
public interface TestMapper {
    //增加信息
    @Insert("INSERT INTO test(name,age,sex,varieties,species,message,time,url)values(#{name},#{age},#{sex},#{varieties},#{species},#{message},#{time},#{url})")
    int addTest(Test t);

    //通过id进行删除信息
    @Delete("DELETE FROM test WHERE id=#{id}")
    int delete(int id);




    //通过id进行查询单条信息
    @Select("SELECT * FROM test WHERE id = #{id}")
    List<Test> select1(@Param("id") int id);

    //通过时间查询信息
    @Select("SELECT * FROM test WHERE time = #{time}")
    List<Test> select2(@Param("time") String time);

    //查询全表
    @Select("SELECT name,age,sex,species,time,other FROM test")
    String select3();

    //查询全表
    @Select("SELECT * FROM test")
    List<Test> select6();

    //查询数据库前十条数据，id自增的时候，是从id最小的开始到第十条最大
    @Select("select * from test where id >= #{id+1} order by id asc limit 10")
    List<Test> select10();


    //根据id加一查询后十条数据
    @Select("select * from test where id >= #{id+1} order by id asc limit 10")
    List<Test> select4(@Param("id") int id);

    //根据id加一查询后x条数据
    @Select("select * from test where id >= #{id+1} order by id asc limit #{num}")
    List<Test> select5(@Param("id") int id,@Param("num") int num);

    //多条件查询
    //1=1的作用是防止语句就变成了 select * from table where ，这时候查询就会报错
    @Select("<script>"+
            "SELECT * FROM test" +
            " WHERE 1=1"+
            "<if test='pa.species!= null'>"+
            "and species = #{pa.species}"+
            "</if>"+
            "<if test='pa.varieties!= null'>"+
            "and varieties = #{pa.varieties}"+
            "</if>"+
            "<if test='pa.sex!= null'>"+
            "and sex = #{pa.sex}"+
            "</if>"+
            "</script>")
    List<Test> selectManyKey(@Param("pa") Test pa);


    @Select("#{admin}")
    List<Test> selectManyKey1(@Param("pa") Test pa);


    //模糊查询（关键字）
    @Select({"select * from test where concat(name,massage) like '%' || 'search_name' || '%' "})
    List<Test> selectKey(@Param("search_name") String search_name);


}